package com.jiangnan.service.Impl;

import com.jiangnan.mapper.EmpMapper;
import com.jiangnan.mapper.StudentMapper;
import com.jiangnan.pojo.JobOption;
import com.jiangnan.pojo.StudentCountOption;
import com.jiangnan.service.ReportService;
import com.jiangnan.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;


    @Override
    public JobOption getEmpJobData() {
        // 1. 调取mapper接口层，获取报表数据
        List<Map<String, Object>> list = empMapper.countEmpJobData();
        // 2. 封装为JobOption对象，返回
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(jobList,dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public StudentCountOption getStudentCountData() {
        // 1. 调用mapper接口层，获取报表数据
        List<Map<String, Object>> studentCountData = studentMapper.getStudentCountData();
        // 2. 封装为StudentCountOption对象，返回
        List<Object> clazzList = studentCountData.stream().map(dataMap -> dataMap.get("name")).toList();
        List<Object> dataList = studentCountData.stream().map(dataMap -> dataMap.get("num")).toList();
        return new StudentCountOption(clazzList,dataList);
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();
    }
}
